﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace CarPCBATest.Procedure
{
    public class TestResultData
    {
        public string SN { get; set; }

        public bool IsOK { get; set; } = true;

        public List<string> NgMsg { get; set; } = new List<string>();

        private static string dir = Environment.CurrentDirectory + "\\Result";

        public static void Note(TestResultData data)
        {
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            string filePath = dir + "\\" + data.SN + ".txt";
            Encoding encoding = Encoding.UTF8;

            // 创建文件流，并打开文件以供读取和写入
            using (FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
            {
                // 写入文本到文件
                using (StreamWriter writer = new StreamWriter(fileStream, encoding))
                {
                    writer.WriteLine($"SN:{data.SN}");

                    writer.WriteLine("测试结果:" + (data.IsOK ? "OK" : "NG"));
                    foreach (string line in data.NgMsg)
                    {
                        writer.WriteLine("测试信息:" + line);
                    }

                    writer.Write($"测试时间:{DateTime.Now.ToString()}");
                }
            }
        }
    }

    public class TestVisionCurrentData
    {
        public double Current { get; set; }
        public bool VisionResult { get; set; }

        public TestVisionCurrentData()
        {
            VisionResult = false;
            Current = 0;
        }

        public string Desc { get; set; }
    }

    public class TestBurnData
    {
        public int McuAddress { get; set; }
        public bool BurnResult { get; set; }
    }
}